use crate::runtime::response::MagicBoxResponse;
use crate::runtime::result::MagicBoxResult;
use crate::state;

#[tauri::command(rename_all = "snake_case")]
pub(crate) async fn invoke_close_window() -> MagicBoxResult<MagicBoxResponse<()>> {
    let window = state::application::application().window();
    if window.is_some() {
        let window = window.unwrap();

        // 先隐藏后关闭，提高响应速度
        let _ = window.hide();

        let result = window.close();
        if result.is_err() {
            log::error!("关闭主窗口失败：{}", result.err().unwrap());
        }

        state::application::application_mut().set_window(None);
    }


    Ok(MagicBoxResponse::new_empty_success())
}
